package com.example.a02back.service.impl;

import cn.hutool.core.util.RandomUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.example.a02back.entity.Card;
import com.example.a02back.mapper.CardMapper;
import com.example.a02back.service.ICardService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author SimpChaos
 * @since 2022-07-14
 */
@Service
public class CardServiceImpl extends ServiceImpl<CardMapper, Card> implements ICardService {



    public Card publish(String uid,String department,String position){
        Card nmd = new Card();
        nmd.setChose("0");
        nmd.setOrgnizinfo(department);
        nmd.setAuthinfo(position);
        nmd.setUid(uid);
        nmd.setCardId(RandomUtil.randomNumbers(14));
        this.save(nmd);
        return nmd;
    }

    public List<Card> getCard(String uid){
        LambdaQueryWrapper<Card> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Card::getUid,uid);
        return this.list(wrapper);
    }

    public String updateCard(Long cardId,String department,String position){
        LambdaUpdateWrapper<Card> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(Card::getCardId,cardId).set(Card::getOrgnizinfo,department).set(Card::getAuthinfo,position);
        return String.valueOf(this.update(wrapper));
    }

    public String deleteCard(String cardId){
        return String.valueOf(this.deleteCard(cardId));
    }




}
